/**
*****************************************************************************
 * DESC ：. 
 * Author : Junwei Zhang 
 * CREATEDATE ：2012-8-26 
 * MODIFYLIST ：       	Name 			 Date 			Reason/Contents
 * 				------------------------------------------------------ 
 * 				 	Junwei Zhang     2012-8-26		Created.
 ****************************************************************************
**/
package com.me.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Collection;
import java.util.List;

/**
 * 
 * <br/> 上午11:50:33 2012-8-26
 * @Author <a href="mailto:mestudying@sina.com">Junwei Zhang</a><br/>
 **/
public class MessageProcessor {

	private Socket socket = null;
	private PrintWriter out = null;
	private BufferedReader in = null;
	private List<String> messageList = null;

	public MessageProcessor(Socket socket) {
		this.socket = socket;
		try {
			out = new PrintWriter(socket.getOutputStream(), true);
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			this.addMessage("connect successfully.");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 向消息列表中添加消息.
	 * @param message
	 */
	private void addMessage(String message) {
		// TODO Auto-generated method stub
		messageList.add(message);
	}

	public void run(){
		String inputLine = null;
		try {
			while ((inputLine = in.readLine()) != null) {
				this.addMessage(inputLine);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送消息.
	 * @param output
	 */
	public void sendMessage(String output) {
		// TODO Auto-generated method stub
		
	}

	public List<String> getMsgList() {
		return messageList;
	}

}
